<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
		<script type="text/javascript" src="wangEditor-3.1.1/release/wangEditor.min.js"></script>
		<link rel="stylesheet" type="text/css" href="layui/css/layui.css" media="all" />
		<script type="text/javascript" src="layui/layui.js"></script>
</head>
<body>
	

		<form class="layui-form" action="">
		  <div class="layui-form-item">
		    <label class="layui-form-label">标题</label>
		    <div class="layui-input-block">
		      <input name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input" type="text">
		    </div>
		  </div>
		  <div class="layui-form-item">
		  
	    <div id="editor" style="background-color: white;">
        	
    	</div>
    	<br/>
	    <label class="layui-form-label">请选择类别</label>
	    <div class="layui-input-block" style="width:200px">
	      <select id="type1" name="type1" lay-filter="type1">
	      </select>
	    </div>
	    <div class="layui-form-item" pane="">
		    <label class="layui-form-label">单选框</label>
		    <div class="layui-input-block">
		      <input name="state" value="0" title="公开" checked="" type="radio">
		      <input name="state" value="1" title="私有" type="radio">
		    </div>
		  </div>
  </div>
  		</form>
		
    	<button type="button" class="layui-btn layui-btn-normal" id="btn1">提 交</button>
</body> 
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
layui.use(['form', 'layedit'], function(){
  var form = layui.form
  ,layedit = layui.layedit;
});
$(function(){
	$.ajax({
		url:'loadtype',
		type:'post',
		success:function(data){
			$.each(data, function (index, item) {
				$('#type1').append(new Option(item.specialty_name, item.specialty_id));
				});
				layui.form.render("select");
		}
	});
})
</script>
<script type="text/javascript">
	//下面这两行脚本就是弹出文本框
	var E = window.wangEditor
	var editor = new E('#editor')
    // 上传图片（举例）
   // editor.customConfig.uploadImgServer = '/upload.ashx'
    editor.customConfig.uploadImgShowBase64 = true   // 使用 base64 保存图片
      //将网络图片隐藏掉
      editor.customConfig.showLinkImg = false
 
     // 将 timeout 时间改为 3s
     editor.customConfig.uploadImgTimeout = 1000 * 10;
 
    editor.customConfig.zIndex = 0;
     document.getElementById('btn1').addEventListener('click', function () {
         // 读取 html
         var blogs=editor.txt.html();
         var title=$("input[name='title']").val();
        console.log(blogs);
        if(title==""||title==null){
        	layer.alert('标题不可为空', {
        		icon: 2,
        		title: "提示"
        	});
        }else{
	        $.ajax({
	        	url:"addblogs",
	        	type:"post",
	        	data:{
	        		title:title,
	        		blogs:blogs,
	        		state:$("input[name='state']:checked").val(),
	        		type:$("#type1").val(),
	        	},
	        	success:function(data){
	        		if(data){
	        			location.href="success"
	        		}else{
	        			layer.alert('啊噢！发生一个异常', {
	        				icon: 5,
	        				title: "错误"
	        				});
	        		}
	        	}
	        })
        }
     }, false)

     editor.create();
    </script>
</html>